home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
comdem
/
commdemo.frm
< prev
next >
Wrap
Text File
|
1995-05-08
|
8KB
|
299 lines
VERSION 2.00
Begin Form CommDemo
BackColor = &H00C0C0C0&
BorderStyle = 1 'Fixed Single
Caption = "Visual Basic Communication Demo"
ClientHeight = 240
ClientLeft = 1245
ClientTop = 1770
ClientWidth = 9090
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontTransparent = 0 'False
FontUnderline = 0 'False
ForeColor = &H00000000&
Height = 930
Icon = COMMDEMO.FRX:0000
Left = 1185
LinkMode = 1 'Source
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 240
ScaleWidth = 9090
Top = 1140
Width = 9210
Begin Menu Menu_File
Caption = "&File"
Begin Menu Menu_File_About
Caption = "&About..."
End
Begin Menu Menu_File_Seperator
Caption = "-"
End
Begin Menu Menu_File_Exit
Caption = "E&xit"
End
End
Begin Menu Menu_Comm
Caption = "&Communications"
Begin Menu Menu_Comm_Connect
Caption = "&Connect"
End
Begin Menu Menu_Comm_Disconnect
Caption = "&Disconnect"
End
Begin Menu Menu_Comm_Filler1
Caption = "-"
End
Begin Menu Menu_Comm_Send_CRLF
Caption = "&Send CR/LF for CR"
End
End
Begin Menu Menu_Settings
Caption = "&Settings"
Begin Menu Menu_Settings_Port
Caption = "&Port Settings..."
End
Begin Menu Menu_Settings_Line
Caption = "&Line Settings..."
End
Begin Menu Menu_Settings_Event
Caption = "&Event Settings..."
End
End
Begin Menu Menu_Windows
Caption = "&Windows"
Enabled = 0 'False
Begin Menu Menu_Window_Receive_Transmit
Caption = "&Receive/Transmit Window..."
End
End
End
Sub Form_Load ()
Initialize
Menu_Comm_Connect.Visible = True
Menu_Comm_Disconnect.Visible = False
offset = 200
CaptionLeft = offset
CaptionTop = offset
CaptionWidth = ScaleWidth - CaptionLeft - offset
CaptionHeight = TextHeight("qypgjXAQK") * 1.5
UpdateCaption " Ready", 0
Left = (Screen.width - width) / 2
top = Height - ScaleHeight
Height = top + CaptionTop + CaptionHeight + offset
End Sub
Sub Form_Paint ()
Draw3d CaptionLeft, CaptionTop, CaptionWidth, CaptionHeight, CommDemo
UpdateCaption CaptionText$, 0
End Sub
Sub Form_Unload (Cancel As Integer)
If CommHandle > -1 Then
Menu_Comm_Disconnect_click
End If
UpdateCaption " Terminating Communication Sampler II...", .5
End Sub
Sub Initialize ()
IndexTrans = 0
IndexReceive = 0
CommHandle = -1
CommDeviceNum = -1
' Default Port Settings
CommPortName = "COM1:"
CommState.BaudRate = 9600
CommState.ByteSize = Chr$(8)
CommState.Parity = Chr$(0)
CommState.StopBits = Chr$(0)
' Default Line Settings
CommRBBuffer = 2048
CommTBBuffer = 2048
CommState.RlsTimeOut = 0
CommState.CtsTimeOut = 0
CommState.DsrTimeOut = 0
CommEventMask = &H3FF
CommReadInterval = 500
' Post-Poned settings
PostRBBuffer = CommRBBuffer
PostTBBuffer = CommTBBuffer
PostEventMask = CommEventMask
PostState = CommState
PostReadInterval = CommReadInterval
PostPortName = CommPortName
End Sub
Sub Menu_Comm_Connect_Click ()
UpdateCaption " Opening Comm Port... " + CommPortName, .5
CommTBBuffer = PostTBBuffer
CommRBBuffer = PostRBBuffer
CommPortName = PostPortName
CommHandle = OpenComm(CommPortName, CommRBBuffer, CommTBBuffer)
If CommHandle = -2 Then
result% = MsgBox("Port already Open!" + Chr$(13) + "Do you want to use it anyway ?", 4 + 16 + 256, "Communication Sampler II")
If result% = 6 Then
ApiErr% = CloseComm(0)
CommHandle = OpenComm(CommPortName, CommRBBuffer, CommTBBuffer)
End If
End If
If CommHandle < 0 Then
UpdateCaption " OpenComm() API Failed! (ERR " + Str$(CommHandle) + ")", .5
Else
Menu_Windows.enabled = True
Menu_Window_Receive_Transmit.Checked = True
Receive.Show
CommEventMask = PostEventMask
CommDeviceNum = Val(Mid$(CommPortName, 4, 1))
ApiErr% = SetCommEventMask(CommHandle, CommEventMask)
PostState = CommState
CommState.Id = Chr$(CommHandle)
ApiErr% = SetCommState(CommState)
Menu_Comm_Connect.Visible = Menu_Comm_Disconnect.Visible
Menu_Comm_Disconnect.Visible = Not Menu_Comm_Connect.Visible
UpdateCaption " Commuications Port Opened...", .5
DisplayQBOpen CommState, CommPortName, CommRBBuffer, CommTBBuffer, CommReadInterval
CommReadInterval = PostReadInterval
Receive.Receive_Timer.interval = CommReadInterval
End If
End Sub
Sub Menu_Comm_Disconnect_click ()
UpdateCaption " Closing Communication Port...", 0
Receive.Receive_Timer.interval = 0
ApiErr% = CloseComm(CommHandle)
CommHandle = -1
CommDeviceNum = -1
Menu_Comm_Disconnect.Visible = Menu_Comm_Connect.Visible
Menu_Comm_Connect.Visible = Not Menu_Comm_Disconnect.Visible
Menu_Windows.enabled = False
Unload Receive
UpdateCaption " Ready", 0
End Sub
Sub Menu_Comm_Send_CRLF_Click ()
Menu_Comm_Send_CRLF.Checked = Not Menu_Comm_Send_CRLF.Checked
End Sub
Sub Menu_File_About_Click ()
UpdateCaption " Loading Dialog...", 0
AboutDlg.Show 1
If Menu_Comm_Connect.Visible = True Then
UpdateCaption " Ready ", 0
Else
UpdateCaption " Communication Port Open...", 0
End If
End Sub
Sub Menu_File_Exit_Click ()
Unload CommDemo
End Sub
Sub Menu_Settings_Event_Click ()
UpdateCaption " Loading Dialog...", 0
EventDlg.Show 1
If Menu_Comm_Connect.Visible = True Then
UpdateCaption " Ready ", 0
Else
UpdateCaption " Communication Port Open...", 0
End If
End Sub
Sub Menu_Settings_Line_Click ()
UpdateCaption " Loading Dialog...", 0
LineDlg.Show 1
If Menu_Comm_Connect.Visible = True Then
UpdateCaption " Ready ", 0
Else
UpdateCaption " Communication Port Open...", 0
End If
End Sub
Sub Menu_Settings_Port_Click ()
UpdateCaption " Loading Dialog...", 0
PortDlg.Show 1
If Menu_Comm_Connect.Visible = True Then
UpdateCaption " Ready ", 0
Else
UpdateCaption " Communication Port Open...", 0
End If
End Sub
Sub Menu_Window_Receive_Transmit_Click ()
Menu_Window_Receive_Transmit.Checked = Not Menu_Window_Receive_Transmit.Checked
If Menu_Window_Receive_Transmit.Checked = True Then
Receive.Show
Receive.Receive_Timer.interval = CommReadInterval
Else
Receive.Hide
End If
End Sub